<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" id="html">

<link href="../pages/style.css" rel="stylesheet" type="text/css">
<link href="local.css" rel="stylesheet" type="text/css">

<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>

<title>MATTE!</title>

<body onload="showContent();" class="body">

<div>
	<div id="firstNumber" class="numbers"></div>
	<div id="regneart" class="numbers"></div>
	<div id="secondNumber" class="numbers"></div>
</div>

<div class="numbers fullWidth">=</div>

<div align="center" style="clear:both;">
	<div id="feedBackPanel" style="color:white;"></div>

	<label>
		<input id="answer" type="text">
	</label>
	<label>
		<br>
		<button type="button" onclick="calculateAnswer();">Sjekk</button>
		<button type="button" onclick="giveUp();">Gir opp</button>

	</label>
</div>

<div class="footer">Copyright Raymond Koteng</div>

</body>

<script language="JavaScript">
	var antallRett = 0;
	var antallForsok = 0;

	function giveUp() {
		antallRett = 0;
		antallForsok = 0;
		document.getElementById("feedBackPanel").innerHTML = "";
		showContent();
	}
	function calculateAnswer() {
		first = document.getElementById("firstNumber").innerHTML;
		second = document.getElementById("secondNumber").innerHTML;
		regneart = document.getElementById("regneart").innerHTML;
		answer = document.getElementById("answer").value;

		var result;

		if (regneart == "+") {
			result = ((parseFloat(first) + parseFloat(second)));
		} else if (regneart == "-") {
			result = ((parseFloat(first) - parseFloat(second)));
		} else if (regneart == "/") {
			result = ((parseFloat(first) / parseFloat(second)));
		} else if (regneart == "*") {
			result = ((parseFloat(first) * parseFloat(second)));
		}

		if (parseFloat(result) == parseFloat(answer)) {
			antallRett ++;
			document.getElementById("feedBackPanel").innerHTML = "Riktig! Antall riktige svar er: " + antallRett;
			showContent();
		} else {
			antallForsok ++;
			if (parseInt(antallForsok) <= 2) {
				document.getElementById("feedBackPanel").innerHTML = "Svaret er feil!";
			} else {
				document.getElementById("feedBackPanel").innerHTML = "Svaret er feil!, riktig svar var: " + result;
				antallRett = 0;
				antallForsok = 0;
				showContent()();
			}
		}
	}

	function showContent() {
		document.getElementById("firstNumber").innerHTML = (Math.floor(Math.random() * 11));
		document.getElementById("regneart").innerHTML = getRegneart();
		document.getElementById("secondNumber").innerHTML = (Math.floor(Math.random() * 11));
		document.getElementById("answer").value = "";

		if (parseInt(document.getElementById("secondNumber").innerHTML) == 0 && document.getElementById("regneart").innerHTML == "/") {
			showContent();
		}
	}

	function getRegneart() {
		var regneartArray = new Array();
		regneartArray[0] = "+";
		regneartArray[1] = "-";
		regneartArray[2] = "*";
		regneartArray[3] = "/";

		return regneartArray[Math.floor(Math.random() * 4)];
	}

</script>

</html>